/**
 * Copyright (c) 2018, dreamkaylee@foxmail.com All Rights Reserved.
 */
  
package configuration;

import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;

/**
 * kaptcha验证码配置类
 * @author limk
 * @date 2018年2月11日 上午11:54:59
 * @version 1.0
 */
@Configuration
public class KaptchaConfig {
	
	private static final Logger LOGGER = LogManager.getLogger(KaptchaConfig.class);
	
	@Bean(name = "captchaProducer")
	public DefaultKaptcha kaptcha() {
		LOGGER.info("----------生成验证码----------");
		DefaultKaptcha kaptcha = new DefaultKaptcha();
		Properties properties = new Properties();
		properties.setProperty("kaptcha.border", "no");
		properties.setProperty("kaptcha.border.color", "105,179,90");
		properties.setProperty("kaptcha.textproducer.font.color", "red");
		properties.setProperty("kaptcha.image.width", "270");
		properties.setProperty("kaptcha.textproducer.font.size", "90");
		properties.setProperty("kaptcha.image.height", "100");
		properties.setProperty("kaptcha.session.key", "code");
		properties.setProperty("kaptcha.textproducer.char.length", "4");
		properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
		Config config = new Config(properties);
		kaptcha.setConfig(config);
		return kaptcha;
	}
}
  